local UI = SecretaryUI

local function ResizeButton_OnMouseDown (self)
	self:GetParent().object:OnResizeStart(self.type)
end

local function ResizeButton_OnMouseUp (self)
	self:GetParent().object:OnResizeStop(self.type)
end

local function ResizeButton_OnEnter (self)
	local type = self.type
	SetCursor("RESIZE_"..type.."_CURSOR")
end

local function ResizeButton_OnLeave (self)
	SetCursor()
end

local ResizeBorderTypes = {
	BOTTOMRIGHT = function (button)
		button:ClearAllPoints()
		button:SetWidth(16)
		button:SetHeight(16)
		button:SetPoint("BOTTOMRIGHT", 0, 0)
	end,
	TOP = function (button)
		button:ClearAllPoints()
		button:SetPoint("TOPLEFT", 2, 0)
		button:SetPoint("TOPRIGHT", -2, -2)
	end,
	BOTTOM = function (button)
		button:ClearAllPoints()
		button:SetPoint("BOTTOMLEFT", 2, 0)
		button:SetPoint("BOTTOMRIGHT", -2, -2)
	end,
	LEFT = function (button)
		button:ClearAllPoints()
		button:SetPoint("TOPLEFT", 2, 0)
		button:SetPoint("BOTTOMLEFT", -2, -2)
	end,
	RIGHT = function (button)
		button:ClearAllPoints()
		button:SetPoint("TOPRIGHT", 2, 0)
		button:SetPoint("BOTTOMRIGHT", -2, -2)
	end,
}

local function CreateResizeButton(parent, type)
	local button = CreateFrame("Frame", nil, parent)
	
	button:EnableMouse(true)
	
	-- button:SetHighlightTexture(UI.CreateTexture(button, ...))
	button.type = type
	button:SetScript("OnMouseDown", ResizeButton_OnMouseDown)
	button:SetScript("OnMouseUp", ResizeButton_OnMouseUp)
	button:SetScript("OnEnter", ResizeButton_OnEnter)
	button:SetScript("OnLeave", ResizeButton_OnLeave)

	ResizeBorderTypes[type](button)
	
	return button
end

UI.CreateResizeButton = CreateResizeButton
UI.ResizeBorderTypes = ResizeBorderTypes